<template>
    <div>
        <a-select :filter-option="filterOption" :value="typeId" placeholder="选择任务类型" show-search @change="handleChange" >
            <a-select-option v-for="(item,index) in typeList" :key="index" :value="item.value">
                {{item.label}}
            </a-select-option>
        </a-select>
    </div>
</template>

<script>
import { setDataForLabel } from '../../utils/util'
import { getAction } from '@api/manage'

export default {
    name: 'SelectLawType',
    props:{
        typesId : {
            type : String,
            default : ''
        }
    },
    data() {
        return {
            typeId : '',
            typeList: [],
        }
    },
    created() {
       this.initData()
    },
    watch:{
        typesId(){
            this.typeId = this.typesId;
        }
    },
    methods: {
        // 初始化查询数据
        async initData() {
            let list = await getAction('/hc/hcLawEnforcementType/typeList')
            this.typeList = setDataForLabel(list.result, 'id', 'typeName');
            // if(this.typeList.length){
            //     let info = this.typeList[0];
            //     if(info){
            //         this.typeId = info.value;
            //         this.$emit('change',info.value,info,null);
            //     }
            // }
        },
        filterOption: function(input, option) {
            return (
                option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
            )
        },

        handleChange : function(value,option) {
            this.typeId = value;
            let info = this.typeList.find((val) => val.value == value);
            this.$emit('change',value,info,option);
        }
    }
}
</script>

<style scoped>

</style>
